let state = {};

class SceneKey {
  constructor() {
    document.addEventListener('keydown', (e) => {
      const ev = e || window.event;
      switch (ev.keyCode) {
        case 87: state.keyCodeW = true; break;
        case 83: state.keyCodeS = true; break;
        case 65: state.keyCodeA = true; break;
        case 68: state.keyCodeD = true; break;
      }
    }, false);
    document.addEventListener('keyup', (e) => {
      const ev = e || window.event;
      switch (ev.keyCode) {
        case 87: state.keyCodeW = false; break;
        case 83: state.keyCodeS = false; break;
        case 65: state.keyCodeA = false; break;
        case 68: state.keyCodeD = false; break;
      }
    }, false);
  }
}
class SceneMove {
  constructor(camera) {
    // 键盘移动  
    if (state.keyCodeW) {
      camera.position.x -= 10;
    }
    if (state.keyCodeA) {
      camera.position.z += 10;
    }
    if (state.keyCodeS) {
      camera.position.x += 10;
    }
    if (state.keyCodeD) {
      camera.position.z -= 10;
    }
    state.keyCodeW = false;
    state.keyCodeA = false;
    state.keyCodeS = false;
    state.keyCodeD = false;
  }
}
export { SceneKey, SceneMove }; 